setfenv(1, require'winapi')
require'winapi.winuser'
require'winapi.cderr'

comdlg = ffi.load'comdlg32'

ffi.cdef[[
DWORD  CommDlgExtendedError(void);
]]

CommDlgExtendedError = comdlg.CommDlgExtendedError

function checkcomdlg(ret)
	if ret == 0 then
		local err = CommDlgExtendedError()
		assert2(err == 0, 'comdlg32 error: %s' % COMMDLG_ERROR_NAMES[err])
		return false --user canceled
	end
	return true
end
